package com.lhgg.examol.util;

import java.util.List;

/**
 * 分页工具类
 * 
 * @author Administrator
 * 
 */
public class PageUtil<T> {
	private int totalRow;
	private int totalPage;
	private int currPage;
	private int beforPage;
	private int afterPage;
	private int pageSize;
	private int startRow;
	private int endRow;
	private List<T> list;

	public PageUtil(int totalRow, int currPage, int pageSize) {
		this.totalRow = totalRow;
		this.currPage = currPage;
		this.pageSize = pageSize;
		this.totalPage = (totalRow % pageSize == 0) ? (totalRow / pageSize)
				: (totalRow / pageSize + 1);
		if (currPage < 1) {
			this.currPage = 1;
		} else if (currPage > totalPage) {
			this.currPage = totalPage;
		} else {
			this.currPage = currPage;
		}
		this.startRow = (this.currPage - 1) * pageSize + 1;
		this.endRow = (this.currPage == this.totalPage) ? (this.totalRow)
				: (this.startRow + pageSize - 1);
		this.beforPage = (1 == this.currPage) ? (1) : (this.currPage - 1);
		this.afterPage = (this.totalPage == this.currPage) ? (this.totalPage)
				: (this.currPage + 1);
	}

	public List<T> getList() {
		return list;
	}

	public PageUtil<T> setList(List<T> list) {
		this.list = list;
		return this;
	}

	public int getTotalRow() {
		return totalRow;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public int getCurrPage() {
		return currPage;
	}

	public int getBeforPage() {
		return beforPage;
	}

	public int getAfterPage() {
		return afterPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getStartRow() {
		return startRow;
	}

	public int getEndRow() {
		return endRow;
	}

}
